package com.aiyige.page.login.presenter;

import com.aiyige.base.eventbus.EventLogin;
import com.aiyige.model.User;
import com.aiyige.page.login.SetPasswordPage;
import com.aiyige.page.login.callbacks.IRegisterCallBack;
import com.aiyige.page.login.model.ISetPasswordModel;
import com.aiyige.page.login.model.impl.SetPasswordImplement;
import com.aiyige.page.login.view.ISetPasswordView;
import com.vondear.rxtools.RxActivityTool;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by xiachao on 2017/8/15.
 */

public class SetPasswordPresenter {
    private ISetPasswordModel mModel;
    private ISetPasswordView mView;
    /**
     * 把Activity的需要用到的model通过ILoginView接口传递到Presenter来
     * @param iSetPasswordView
     */
    public SetPasswordPresenter(ISetPasswordView iSetPasswordView)
    {
        this.mView = iSetPasswordView;
        this.mModel = new SetPasswordImplement();
        mModel.setView(mView);
    }


    public void bindPhoneAndPassword() {
        mModel.bindPhoneAndPassword(mView.getCode(),mView.getMobile(), mView.getPassword(),mView.getThirdOauthBackup(), new IRegisterCallBack()
        {
            @Override
            public void success(User session) {
                //SessionUtil.updateCurrentSession(session);
                EventBus.getDefault().post(new EventLogin(session));
                RxActivityTool.finishActivity(SetPasswordPage.class);
            }

            @Override
            public void error(String errorCode) {
            }

        });
    }

    public void setPassword()
    {
        mModel.setPassword(mView.getCode(),mView.getMobile(), mView.getPassword(), new IRegisterCallBack()
        {
            @Override
            public void success(User session) {
                //SessionUtil.updateCurrentSession(session);
                EventBus.getDefault().post(new EventLogin(session));
                RxActivityTool.finishActivity(SetPasswordPage.class);
            }

            @Override
            public void error(String errorCode) {
            }

        });
    }
}
